package sng.modules.view.components.city.logic.unit
{
	import core.interfaces.IDispose;
	
	import flash.events.Event;

	//建筑操作队列 create by royjin 20110711
	public final class BuildingQueue extends Object implements IDispose
	{
		private var waitList:Array
		
		public function BuildingQueue()
		{
			waitList = new Array();
		}
		public function dispose():void
		{
			waitList = new Array();
		}
		//添加一个需要操作的建筑到队列
		public function AddBuilding(bd:BaseBuilding):void
		{
			waitList.push(bd);
			bd.skin.alpha = 0.5;
			bd.skin.mouseEnabled = false;
			bd.skin.mouseChildren = false;
			if(waitList.length==1)
			{
				this.ReadQueue();
			}
		}
		
		//从队列中取出对象进行建筑操作
		private function ReadQueue():void
		{
			if(waitList.length>0)
			{
				var bd:BaseBuilding = waitList[0] as BaseBuilding;
				bd.skin.alpha = 1;
				bd.skin.mouseEnabled = true;
				bd.skin.mouseChildren = true;
				//进行建筑逻辑,添加操作完成消息
				bd.setProgress();
				bd.progress.addEventListener("progressOver", OnOperationComplete, false, 0, true);
			}
		}
		//当一个建筑操作完成,继续读取下一个操作执行
		private function OnOperationComplete(e:Event):void
		{
			e.target.removeEventListener("progressOver", OnOperationComplete);
			waitList.shift();
			ReadQueue();
		}
	}
}